﻿
@{
    ViewBag.Title = "Select";
    Layout = "~/Areas/admin/Views/Shared/_Layout.cshtml";
    List<One_day.Models.T_Base_User> user = ViewBag.user;
}

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <h1 class="page-header">订单检索</h1>
        </div>
    </div>
    <label>筛选日期</label>
    <form name="date" action="/admin/order/selectresult">
        <div>
            <label>起始：</label>
            <select name="year_from" onchange="selectYear(this.value)" id="year_from" >
                <option value="">选择 年</option>
            </select>
            <select name="month_from" onchange="selectMonth(this.value)" id="month_from">
                <option value="">选择 月</option>
            </select>
            <select name="day_from" id="day_from">
                <option value="">选择 日</option>
            </select>
        </div>
        <br />
        <div>
            <label>截至：</label>
            <select name="year_to" onchange="selectYear(this.value)" id="year_to">
                <option value="">选择 年</option>
            </select>
            <select name="month_to" onchange="selectMonth(this.value)" id="month_to">
                <option value="">选择 月</option>
            </select>
            <select name="day_to" id="day_to">
                <option value="">选择 日</option>
            </select>
        </div>
        <br />
        <button type="submit" class="btn btn-primary" onclick="sub_infor()">查询</button>
    </form>

    
</div>
@section js{
    <script language="JavaScript">

        

        //from
        function dateStart_from() {
            //月份对应天数
            MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

            //给年下拉框赋内容
            var y = new Date().getFullYear();
            for (var i = (y - 50); i < (y+1); i++) //以今年为准，前50年
                document.date.year_from.options.add(new Option(" " + i + " 年", i));

            //给月下拉框赋内容
            for (var i = 1; i < 13; i++)
                document.date.month_from.options.add(new Option(" " + i + " 月", i));

            document.date.year_from.value = y;
            document.date.month_from.value = new Date().getMonth() + 1;
            var n = MonHead[new Date().getMonth()];
            if (new Date().getMonth() == 1 && IsPinYear(yearvalue))
                n++;
            writeDay_from(n); //赋日期下拉框
            document.date.day_from.value = new Date().getDate();
        }

        if (document.attachEvent)
            window.attachEvent("onload", dateStart_from);
        else
            window.addEventListener('load', dateStart_from, false);

        function selectYear(str) //年发生变化时日期发生变化(主要是判断闰平年)
        {
            var monthvalue = document.date.month_from.options[document.date.month_from.selectedIndex].value;
            if (monthvalue == "") {
                var e = document.date.day_from;
                optionsClear(e);
                return;
            }
            var n = MonHead[monthvalue - 1];
            if (monthvalue == 2 && IsPinYear(str))
                n++;
            writeDay_from(n);
        }

        function selectMonth(str)   //月发生变化时日期联动
        {
            var yearvalue = document.date.year_from.options[document.date.year_from.selectedIndex].value;
            if (yearvalue == "") {
                var e = document.date.day_from;
                optionsClear(e);
                return;
            }
            var n = MonHead[str - 1];
            if (str == 2 && IsPinYear(yearvalue))
                n++;
            writeDay_from(n);
        }

        function writeDay_from(n)   //据条件写日期的下拉框
        {
            var e = document.date.day_from; optionsClear(e);//先将下拉框恢复为一个，在填充数据
            for (var i = 1; i < (n + 1); i++)
                e.options.add(new Option(" " + i + " 日", i));
        }

        function IsPinYear(year)//判断是否闰平年
        {
            return (0 == year % 4 && (year % 100 != 0 || year % 400 == 0));
        }

        function optionsClear(e) {
            e.options.length = 1;
        }

        //to
        function dateStart_to() {
            //月份对应天数
            MonHead = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

            //给年下拉框赋内容
            var y = new Date().getFullYear();
            for (var i = (y - 50); i < (y + 1); i++) //以今年为准，前50年
                document.date.year_to.options.add(new Option(" " + i + " 年", i));

            //给月下拉框赋内容
            for (var i = 1; i < 13; i++)
                document.date.month_to.options.add(new Option(" " + i + " 月", i));

            document.date.year_to.value = y;
            document.date.month_to.value = new Date().getMonth() + 1;
            var n = MonHead[new Date().getMonth()];
            if (new Date().getMonth() == 1 && IsPinYear(yearvalue))
                n++;
            writeDay_to(n); //赋日期下拉框
            document.date.day_to.value = new Date().getDate();
        }

        if (document.attachEvent)
            window.attachEvent("onload", dateStart_to);
        else
            window.addEventListener('load', dateStart_to, false);

        function selectYear(str) //年发生变化时日期发生变化(主要是判断闰平年)
        {
            var monthvalue = document.date.month_to.options[document.date.month_to.selectedIndex].value;
            if (monthvalue == "") {
                var e = document.date.day_to;
                optionsClear(e);
                return;
            }
            var n = MonHead[monthvalue - 1];
            if (monthvalue == 2 && IsPinYear(str))
                n++;
            writeDay_to(n);
        }

        function selectMonth(str)   //月发生变化时日期联动
        {
            var yearvalue = document.date.year_to.options[document.date.year_to.selectedIndex].value;
            if (yearvalue == "") {
                var e = document.date.day_to;
                optionsClear(e);
                return;
            }
            var n = MonHead[str - 1];
            if (str == 2 && IsPinYear(yearvalue))
                n++;
            writeDay_to(n);
        }

        function writeDay_to(n)   //据条件写日期的下拉框
        {
            var e = document.date.day_to; optionsClear(e);
            for (var i = 1; i < (n + 1); i++)
                e.options.add(new Option(" " + i + " 日", i));
        }

        function IsPinYear(year)//判断是否闰平年
        {
            return (0 == year % 4 && (year % 100 != 0 || year % 400 == 0));
        }

        function optionsClear(e) {
            e.options.length = 1;
        }
        
    </script>
}
